<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选择模型 - 河域分割系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">河域分割系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('dashboard') }}">仪表板</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.my_data') }}">我的数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.upload') }}">上传数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('analysis.time_series_analysis') }}">时间分析</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> {{ current_user.username }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="#">个人资料</a></li>
                            <li><a class="dropdown-item" href="#">设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">退出登录</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <div class="container my-4">
        <div class="row mb-4">
            <div class="col-md-8">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{{ url_for('data.my_data') }}">我的数据</a></li>
                        <li class="breadcrumb-item"><a href="{{ url_for('data.image_detail', image_id=image.id) }}">{{ image.filename.split('_', 1)[1] }}</a></li>
                        <li class="breadcrumb-item active">选择模型</li>
                    </ol>
                </nav>
                <h2>选择预测模型</h2>
                <p class="text-muted">为数据 "{{ image.filename.split('_', 1)[1] }}" 选择使用的水域分割模型</p>
            </div>
            <div class="col-md-4 text-end">
                <a href="{{ url_for('data.image_detail', image_id=image.id) }}" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-left"></i> 返回数据详情
                </a>
            </div>
        </div>

        <!-- 加载指示器 -->
        <div id="loadingIndicator" class="alert alert-info d-none">
            <div class="d-flex align-items-center">
                <div class="spinner-border spinner-border-sm me-2" role="status">
                    <span class="visually-hidden">加载中...</span>
                </div>
                <div>
                    正在进行预测，请稍候...
                </div>
            </div>
        </div>

        <!-- 错误提示 -->
        <div id="errorAlert" class="alert alert-danger d-none">
            <div class="d-flex align-items-center">
                <i class="bi bi-exclamation-triangle me-2"></i>
                <div id="errorMessage">
                    发生错误
                </div>
            </div>
        </div>

        <!-- 模型选择卡片 -->
        <div class="row">
            <div class="col-md-4 mb-4">
                <div class="card h-100 model-card">
                    <div class="card-header bg-primary text-white">
                        <h5 class="mb-0">U-Net 模型</h5>
                    </div>
                    <div class="card-body">
                        <p class="card-text">U-Net是一种流行的深度学习分割模型，特别适用于图像分割任务。</p>
                        <ul>
                            <li>优势：结构简单，训练快速</li>
                            <li>适用：一般河流分割场景</li>
                            <li>精度：中等-高</li>
                        </ul>
                    </div>
                    <div class="card-footer bg-transparent border-0">
                        <form class="prediction-form" data-model="unet">
                            <input type="hidden" name="model" value="unet">
                            <button type="submit" class="btn btn-primary w-100">
                                <i class="bi bi-play-fill"></i> 使用U-Net模型
                            </button>
                        </form>
                    </div>
                </div>
            </div>
            <div class="col-md-4 mb-4">
                <div class="card h-100 model-card">
                    <div class="card-header bg-success text-white">
                        <h5 class="mb-0">U2-Net 模型</h5>
                    </div>
                    <div class="card-body">
                        <p class="card-text">U2-Net是U-Net的改进版本，具有更深的网络结构和更好的特征提取能力。</p>
                        <ul>
                            <li>优势：精度高，细节保留好</li>
                            <li>适用：复杂河流形态场景</li>
                            <li>精度：高</li>
                        </ul>
                    </div>
                    <div class="card-footer bg-transparent border-0">
                        <form class="prediction-form" data-model="u2net">
                            <input type="hidden" name="model" value="u2net">
                            <button type="submit" class="btn btn-success w-100">
                                <i class="bi bi-play-fill"></i> 使用U2-Net模型
                            </button>
                        </form>
                    </div>
                </div>
            </div>
            <div class="col-md-4 mb-4">
                <div class="card h-100 model-card">
                    <div class="card-header bg-info text-white">
                        <h5 class="mb-0">MNDWI 方法</h5>
                    </div>
                    <div class="card-body">
                        <p class="card-text">MNDWI是一种传统的水体提取指数，基于多光谱卫星图像中的不同波段计算。</p>
                        <ul>
                            <li>优势：计算快速，无需训练</li>
                            <li>适用：多光谱卫星图像</li>
                            <li>精度：中等</li>
                        </ul>
                    </div>
                    <div class="card-footer bg-transparent border-0">
                        <form class="prediction-form" data-model="mndwi">
                            <input type="hidden" name="model" value="mndwi">
                            <button type="submit" class="btn btn-info w-100 text-white">
                                <i class="bi bi-play-fill"></i> 使用MNDWI方法
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- 模型比较说明 -->
        <div class="row mt-3">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">模型比较</h5>
                    </div>
                    <div class="card-body">
                        <p>不同模型在不同场景下有各自的优势，您可以尝试多种模型并比较结果。</p>
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>模型</th>
                                        <th>适用场景</th>
                                        <th>速度</th>
                                        <th>精度</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>U-Net</td>
                                        <td>一般河流场景</td>
                                        <td>快</td>
                                        <td>中-高</td>
                                    </tr>
                                    <tr>
                                        <td>U2-Net</td>
                                        <td>复杂河流场景</td>
                                        <td>慢</td>
                                        <td>高</td>
                                    </tr>
                                    <tr>
                                        <td>MNDWI</td>
                                        <td>多光谱卫星图像</td>
                                        <td>极快</td>
                                        <td>中</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-4 mt-5">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h5>河域分割系统</h5>
                    <p>基于深度学习的河域分割与分析平台</p>
                </div>
                <div class="col-md-3">
                    <h5>链接</h5>
                    <ul class="list-unstyled">
                        <li><a href="{{ url_for('index') }}" class="text-white">首页</a></li>
                        <li><a href="{{ url_for('dashboard') }}" class="text-white">仪表板</a></li>
                        <li><a href="{{ url_for('data.my_data') }}" class="text-white">我的数据</a></li>
                    </ul>
                </div>
                <div class="col-md-3">
                    <h5>账户</h5>
                    <ul class="list-unstyled">
                        <li><a href="#" class="text-white">个人资料</a></li>
                        <li><a href="#" class="text-white">设置</a></li>
                        <li><a href="{{ url_for('auth.logout') }}" class="text-white">退出登录</a></li>
                    </ul>
                </div>
            </div>
            <hr>
            <div class="text-center">
                <p>&copy; 2023 河域分割系统. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const forms = document.querySelectorAll('.prediction-form');
            const loadingIndicator = document.getElementById('loadingIndicator');
            const errorAlert = document.getElementById('errorAlert');
            const errorMessage = document.getElementById('errorMessage');
            
            forms.forEach(form => {
                form.addEventListener('submit', function(e) {
                    e.preventDefault();
                    
                    // 显示加载中状态
                    loadingIndicator.classList.remove('d-none');
                    errorAlert.classList.add('d-none');
                    
                    // 禁用所有提交按钮
                    document.querySelectorAll('.prediction-form button[type="submit"]').forEach(button => {
                        button.disabled = true;
                    });
                    
                    const modelType = this.getAttribute('data-model');
                    const formData = new FormData();
                    formData.append('model', modelType);
                    
                    // 发送AJAX请求
                    fetch('{{ url_for("prediction.process_image", image_id=image.id) }}', {
                        method: 'POST',
                        body: formData,
                        headers: {
                            'X-Requested-With': 'XMLHttpRequest'
                        }
                    })
                    .then(response => response.json())
                    .then(data => {
                        loadingIndicator.classList.add('d-none');
                        
                        if (data.success) {
                            // 成功 - 重定向到结果页面
                            window.location.href = data.redirect_url;
                        } else {
                            // 显示错误信息
                            errorMessage.textContent = data.message || '预测失败，请重试';
                            errorAlert.classList.remove('d-none');
                            
                            // 重新启用按钮
                            document.querySelectorAll('.prediction-form button[type="submit"]').forEach(button => {
                                button.disabled = false;
                            });
                        }
                    })
                    .catch(error => {
                        loadingIndicator.classList.add('d-none');
                        errorMessage.textContent = '发生错误：' + error.message;
                        errorAlert.classList.remove('d-none');
                        
                        // 重新启用按钮
                        document.querySelectorAll('.prediction-form button[type="submit"]').forEach(button => {
                            button.disabled = false;
                        });
                    });
                });
            });
        });
    </script>
</body>
</html> 